package cn1shared.ui;

import com.codename1.ui.Command;
import com.codename1.ui.Component;
import com.codename1.ui.Container;
import com.codename1.ui.Form;
import com.codename1.ui.Image;
import com.codename1.ui.layouts.BoxLayout;


public class MessageForm extends AbstractForm {

	private Object[] elements;

	public MessageForm(String title, Object... elements) {
		super(title);
		this.elements = elements;
		getTitleComponent().getStyle().setAlignment(Component.CENTER);
	}

	public MessageForm(String title, Form parent, Object... elements) {
		super(title, parent);
		this.elements = elements;
		getTitleComponent().getStyle().setAlignment(Component.CENTER);
	}

	@Override
	protected Container getPanel()
	{
		BoxLayout layout = new BoxLayout(BoxLayout.Y_AXIS);
		Container panel = FormUtils.newContainer(layout);
		panel.setScrollableY(true);
		for (Object e : this.elements) {
			if (e instanceof String) {
				String txt = (String) e;
				panel.addComponent(FormUtils.newTextLabel(txt));
			} else if (e instanceof Image) {
				panel.addComponent(FormUtils.newLabel((Image) e).alignCenter());
			} else if (e instanceof Command) {
				Command cmd = (Command) e;
				panel.addComponent(FormUtils.newButton(cmd));
			}
		}
		return panel;
	}
}
